package com.ruoyi.web.controller.api;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.wcf.service.*;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * app-型号检索
 * @author zhipeng
 */
@RestController
@RequestMapping("/api/productSearch")
public class ApiProductSearchController {

    @Resource
    private IWcfProductClassService productClassService;
    @Resource
    private IWcfProductModelService productModelService;
    @Resource
    private IWcfMobileBrandService mobileBrandService;
    @Resource
    private IWcfMobileSeriesService mobileSeriesService;
    @Resource
    private IWcfMobileModelService mobileModelService;

    /**
     * 产品分类列表
     * @return
     */
    @GetMapping("/productClassList")
    public AjaxResult productClassList(){
        try {
            return AjaxResult.success(productClassService.productClassList());
        }catch (Exception e){
            e.printStackTrace();
            return AjaxResult.error("服务器异常");
        }
    }

    /**
     * 手机品牌列表
     * @return
     */
    @GetMapping("/mobileBrandList")
    public AjaxResult mobileBrandList(){
        try {
            return AjaxResult.success(mobileBrandService.mobileBrandList());
        }catch (Exception e){
            e.printStackTrace();
            return AjaxResult.error("服务器异常");
        }
    }

    /**
     * 手机系列列表
     * @return
     */
    @GetMapping("/mobileSeriesList")
    public AjaxResult mobileSeriesList(@RequestParam Map<String,Object> map){
        try {
            if (!map.containsKey("brandId") || StringUtils.isBlank(map.get("brandId").toString())){
                return AjaxResult.error("缺少参数");
            }
            return AjaxResult.success(mobileSeriesService.mobileSeriesList(map));
        }catch (Exception e){
            e.printStackTrace();
            return AjaxResult.error("服务器异常");
        }
    }

    /**
     * 手机型号列表
     * @return
     */
    @GetMapping("/mobileModelList")
    public AjaxResult mobileModelList(@RequestParam Map<String,Object> map){
        try {
            if (!map.containsKey("seriesId") || StringUtils.isBlank(map.get("seriesId").toString())){
                return AjaxResult.error("缺少参数");
            }
            return AjaxResult.success(mobileModelService.mobileModelList(map));
        }catch (Exception e){
            e.printStackTrace();
            return AjaxResult.error("服务器异常");
        }
    }

    /**
     * 检索产品
     * @return
     */
    @PostMapping("/searchProduct")
    public AjaxResult searchProduct(@RequestBody Map<String,Object> map){
        try {
            if (!map.containsKey("classId")
                    ||!map.containsKey("modelIdList")
            ){
                return AjaxResult.error("缺少参数");
            }
            return AjaxResult.success(productModelService.searchProduct(map));
        }catch (Exception e){
            e.printStackTrace();
            return AjaxResult.error("服务器异常");
        }
    }

}
